Using Node.js

Setting up your environment

This page describes the steps to set up node.js.


What is Node?

Node.js allows you to run javascript at the back-end, i.e. on a web server or you computer. This contrasts with running javascript in the browser.

Node.js provides a wealth of functionlity that would not be available if we restrict ourselves to running javascript in the browser.

Installing Node

Download and install node from here:

node.js Node website

Install the LTS version.

You can choose all the default options when you install it.

Installing Visual Studio Code

You will need an IDE (Integrated Development Environment) to edit your code. I like to use Visual Studio Code, but there are numerous other options.

To install Visual Studio Code, go here:

Visual Studio Code Vs code

A simple first project

Create a new folder called "hello" on your desktop.

Start up Visual Studio Code (VS Code):

Vsc 1

Open the "hello" folder in VS Code by either selecting it using the File->Open Folder menu or dragging the hello folder into VS Code. You should see the folder open in the explorer in VS Code:

Vsc 2

Click on the new file icon:

Vsc 3

Create a file called hello.js:

Vsc 4

Enter code as follows into the file:

Vsc 5

Save the file, then start the terminal using the Terminal->New Terminal menu. You should see something like this:

Vsc 6

Type "node hello.js" into the terminal:

Vsc 7

Then hit ENTER. You should see the message "Hello World" show in ther terminal:

Vsc 8

Congratulations, you've written your first node.js code!

Glitch: An alternative to running node.js and and IDE on your computer

Glitch is a hosting platform for running node.js applications in the cloud. You can edit your code directly in the browser and run your application on Glitch's servers. You can even share your application instantly. It's a nice alternative to installing node.js and an IDE on your local computer.

Find out more about Glitch here:

Glitch